#include "memento.h"

Memento::Memento()
{
    keepers = new QStack<ScoreKeeper*>();
    players= new QStack<QList<PlayerIcon*>* >();
}

void Memento::saveState(ScoreKeeper* keeper, QList<PlayerIcon*>* player){
    ScoreKeeper* savedKeeper = new ScoreKeeper(keeper);
    keepers->push(savedKeeper);
    QList<PlayerIcon*>* currentPlayers= new QList<PlayerIcon*>();
    for(int i=0; i<player->size();i++){
        currentPlayers->append(new PlayerIcon(player->at(i)));
    }
    players->push(currentPlayers);
}

void Memento::revertState(ScoreKeeper* currentKeeper, QList<PlayerIcon*>* player ){
    if(keepers->size()>0 && players->size()>0){
        currentKeeper = keepers->pop();
        player= players->pop();
    }
}

ScoreKeeper* Memento::getLastKeeper(){
    if(keepers->size()==0){
        return 0;
    }

    return keepers->pop();
}

QList<PlayerIcon*>* Memento::getLastPlayers(){
    if(players->size()==0){
        return 0;
    }
    return players->pop();
}
